﻿using UnityEngine;
using System.Collections;

public class Boss01Controller : MonoBehaviour {

    public GameObject [] activeBullet;

    public GameObject[] Bullets;

    public Transform[] transformBullets;

    public Collider[] colliderSub;

    private bool flag01,flag02,flagHead;

    private EnemyController enemyController;

    private float timeBullet01;

    private float timeBullet02;

    private int plus;
    void Awake()
    {
        plus = 0;
        enemyController = GetComponent<EnemyController>();
    }
    
    void FixedUpdate()
    {

        if (enemyController.status.Health < 300)
        {
            plus = 1;
            colliderSub[0].enabled = false;
        }
       
        if (enemyController.status.Health > 200)
        {
           

            if (activeBullet[0].active && !flag01)
            {
                Shoot(0 + plus, 2, 0, 2);
                flag01 = true;
            }

            else if (!activeBullet[0].active)
            {
                flag01 = false;
            }

            if (activeBullet[1].active && !flag02)
            {
                Shoot(2 + plus, 4, 2, 4);
                flag02 = true;
            }

            else if (!activeBullet[1].active)
            {
                flag02 = false;
            }
        }
        else
        {
            timeBullet01 += Time.deltaTime;
            timeBullet02 += Time.deltaTime;
            if (timeBullet01 >= 6)
            {
               

                Shoot(4, 6, 4, 4);
            }

            if (timeBullet02 >= 4)
            {
                Instantiate(Bullets[Bullets.Length - 1], transformBullets[6].position, Bullets[Bullets.Length - 1].transform.rotation);
                Instantiate(Bullets[Bullets.Length - 1], transformBullets[7].position, Bullets[Bullets.Length - 1].transform.rotation);
                timeBullet02 = 0;
            }
            
           
                colliderSub[1].enabled = false;
        }
    }

    void Shoot(int index,int n,float minRandom,float maxRandom)
    {
        for (int i = index; i < n; i++)
        {
            int temp=(int)Random.Range(minRandom,maxRandom);
            Instantiate(Bullets[temp], transformBullets[i].position, Bullets[temp].transform.rotation);
        }
        timeBullet01 = 0;
    }
}
